//index.js
//获取应用实例
const app = getApp()
const Api = require("../../utils/api.js").API
const Store = require("../../utils/store.js").store
const codeZ = require("../../utils/util.js")
Page({
    data: {
        show: false,
        ErShow: false,
        haha: '',
        userStatus:{'ckName':'','ckType':''},
        sum: 1,
        sumZF: 1,
        bb:'',
        list: {
            banners: {
                contentList: [],
            },
            searchs: {
                contentList: [1],
            },
            evaluations: {
                contentList: [],
            },
            productRecommends: {
                contentList: []
            },

        },
         animate: false,
        msgList: [
          {
            context: "三三**，李西**，记得**，正在下单"
           
          },
          {
            context: "刘*，小可*，待定**，正在下单",
           
          },
          {
            context: "诸**，小小*，不可*，正在进行下单",
           
          },
          {
            context: "孙*，李*，无天， 正在下单",
           
          },
          {
          context: "孙*，李*，无天，正在下单",
           
          },
          {
            context: "散散和海**，李*，刘提阿**， 正在下单",
           
          },
          {
             context: "筋骨*，李是拒绝*，天天冉ran*， 正在下单",
           
          },
          {
             context: "和海*，不回头*，吐古*， 正在下单",
           
          },
          {
             context: "瞽*，等不及*，无*， 正在下单",
           
          },
          {
             context: "结局*，李*，wix*， 正在下单",
           
          },
          {
             context: "wxj*，all*，WiFi*， 正在下单",
           
          },
          {
             context: "看聚*，悠然一缝*，捷尔*， 正在下单",
           
          },
          {
             context: "仙女你*，数据*，发*， 正在下单",
           
          },
          {
             context: "数据*，以后让*，老爱*， 正在下单",
           
          },
          {
             context: "WiFi*，嗯哦哦*，WiFi*， 正在下单",
           
          },

          {
             context: "孙非*，IEIE*，为自己*， 正在下单",
           
          },
          {
             context: "湖**，信念*，scjjcsjc*， 正在下单",
           
          }
        ],
                
          userInfo:'',
    
    },
    catchTouchMove:function(res){
       return false
     },

    onLoad(options) {
      //参数拼接在后面即可
        wx.setStorageSync('ckid','');
        if (options.source == "detailPage") {
            wx.redirectTo({
                url: '../DetailData/index?item=' + options.sence + '&custNo='+options.custNo,
            }) //参数拼接在后面即可
            
        }else if(options.source == 'shopPage'){
           
            wx.redirectTo({
                url: '../shopDetail/index?skuNo=' + options.skuNo + '&custNo='+options.custNo,
            }) //参数拼接在后面即可
        }else if(options.source == 'lpPage'){
            wx.redirectTo({
                url: '../MyScanCard/index?ckid=' + options.sence,
            }) //参数拼接在后面即可
        }
    },
    onShow: function() {
        
        
        
        var data = {
            'coNo': 'CO1608195431952541'
        }
        var token = Store.getStore('token');
        // debugger
        if (token == null || token == "") {
            Api.selsectPointApi(data).then(res => {
                if (res.code == 0) {
                    Store.setStore('token', res.token);
                }
            })
        }
        
     let ckNo = wx.getStorageSync('ckNo');
     if(ckNo){
         
     
     Api.getCkInfoApi(ckNo).then(res=>{
         if(res.data == null){
             return
         }
          wx.setStorageSync('baseInfo',res.data);
           if(res.data.hasOwnProperty('ckType')){
               this.setData({
                   userStatus:res.data
               })
           }else{
               this.setData({
                   userStatus:{'ckName':'','ckType':''}
               })
           }
         
     })
     }else{
         let a =  wx.getStorageSync('baseInfo');
           if(a.hasOwnProperty('ckType')){
               this.setData({
                   userStatus:a
               })
           }else{
               this.setData({
                   userStatus:{'ckName':'','ckType':''}
               })
           }
     }
     
     
     
        


        var data = {
            'coNo': 'CO1606461267364471'
        }
        this.setData({
            haha: app.globalData.options
        })
        var token = Store.getStore('token');
        if (token == null || token == "") {
            Api.selsectPointApi(data).then(res => {
                if (res.code == 0) {
                    Store.setStore('token', res.token);
                }
            })
        }
        let that = this;
        var shre = wx.getStorageSync('share');

        if (shre != null && shre == 'share') {
            this.setData({
                show: true
            });
        }
        let data2 = {
            'evTitle': ''
        }
        this.loadData(data2);
    },
    findMore: function() {
        wx.switchTab({
            url: '../CePing/index'
        })
    },
    loadData: function(data) {
        
        let that = this;
        Api.getPageSetUpApi(data).then(res => {
                
            if(res.list.length == 0){
                return;
            }
            let arr = res.list[0].modulList;
            if (arr.length == 0) {
                return;
            }
            arr.forEach(item => {
                if (item.pmName == 'banner') {
                    that.setData({
                        ['list.banners']: item
                    })
                } else if (item.pmName == '搜索') {
                    that.setData({
                        ['list.searchs']: item
                    })
                } else if (item.pmName == '评测') {
                    that.setData({
                        ['list.evaluations']: item
                    })
                } else if (item.pmName == '商品推荐') {
                    that.setData({
                        ['list.productRecommends']: item
                    })
                }
            })
        })
    },
    sure() {

        wx.setStorageSync("share", "")
        this.setData({
            show: false
        });
    },

    clickJumpDetail: function() {
        wx.switchTab({
            url: '../GoodsList/index'
        })
    },
    clickJJ: function() {
      
    
    
   
        wx.navigateTo({
            url: '../DetailData/index?type=1',
            success: function(res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('acceptDataFromOpenerPage', {
                    data: 'EV2021020513009147240448'
                })
            }
        })
    },
    clickSK:function(){
       wx.navigateTo({
           url: '../DetailData/index?type=1',
           success: function(res) {
               // 通过eventChannel向被打开页面传送数据
               res.eventChannel.emit('acceptDataFromOpenerPage', {
                   data: 'EV2021020513009321647104'
               })
           }
       }) 
    },
    clickCG:function(){
        wx.navigateTo({
            url: '../DetailData/index?type=1',
            success: function(res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('acceptDataFromOpenerPage', {
                    data: 'EV2021020513006879899136'
                })
            }
        })
    },
    clickJump: function(e) {
      
     let i = e.currentTarget.dataset.item['busiNo'];
    
    if(i == null || i == ""){
           return 
    }
        wx.navigateTo({
            url: '../DetailData/index',
            success: function(res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('acceptDataFromOpenerPage', {
                    data: i
                })
            }
        })
    },
    onShareAppMessage: function() {
        var that = this;
        let url = encodeURIComponent('pages/index/index?goods=' + this.data.goods);
        Api.ByShareApi().then(res => {
            if (res.code == 0 && res.data != null) {
                if (res.data.length != 0) {
                    wx.setStorageSync("share", "share");
                    that.setData({
                        sum: res.data.length
                    })

                }
            }
        })
        return {
            title: "商品详情",
            path: `/pages/index/index`,
            success: function(res) {
                // 转发成功之后的回调
                if (res.errMsg == 'shareAppMessage:ok') {
                    console.log('2')
                }
            },


        }
    },

    jumpDe: function(e) {
        let i = e.currentTarget.dataset.item;
        if(i.busiNo == null || i.busiNo == ""){
               return 
        }
        let str = {
            'skuNo': i.busiNo
        };
        console.log(i);
        wx.navigateTo({
            url: '../shopDetail/index',
            success: function(res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('acceptDataFromOpenerPage', {
                    data: str
                })
            }
        })
    },
    onSerach(e) {
        this.setData({
            value: e.detail
        })

    },
    onSureSearch: function() {

        let data = {
            'evTitle': this.data.value
        }

        this.loadData(data);
    }




});
